﻿using AutomatedTestDataManagement.Models;
using System.Data;
using System.Linq;
using System.Web.Mvc;

namespace AutomatedTestDataManagement.Controllers
{
    public class DataTableController : Controller
    {
        private ApplicationTestDataEntities db = new ApplicationTestDataEntities();

        //
        // GET: /DataTable/

        public ActionResult Index()
        {
            return View(db.ViewDataTables.ToList());
        }

        [ChildActionOnly]
        public ActionResult _ListDataTables()
        {
            var datatableList = db.ViewDataTables.ToList();
            return PartialView(datatableList);
        }
        //
        // GET: /DataTable/Details/5

        public ActionResult Details(string id = null)
        {
            ViewDataTable viewdatatable = db.ViewDataTables.Find(id);
            if (viewdatatable == null)
            {
                return HttpNotFound();
            }
            return View(viewdatatable);
        }

        //
        // GET: /DataTable/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /DataTable/Create

        [HttpPost]
        public ActionResult Create(ViewDataTable viewdatatable)
        {
            if (ModelState.IsValid)
            {
                db.ViewDataTables.Add(viewdatatable);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(viewdatatable);
        }

        //
        // GET: /DataTable/Edit/5

        public ActionResult Edit(string id = null)
        {
            ViewDataTable viewdatatable = db.ViewDataTables.Find(id);
            if (viewdatatable == null)
            {
                return HttpNotFound();
            }
            return View(viewdatatable);
        }

        //
        // POST: /DataTable/Edit/5

        [HttpPost]
        public ActionResult Edit(ViewDataTable viewdatatable)
        {
            if (ModelState.IsValid)
            {
                db.Entry(viewdatatable).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(viewdatatable);
        }

        //
        // GET: /DataTable/Delete/5

        public ActionResult Delete(string id = null)
        {
            ViewDataTable viewdatatable = db.ViewDataTables.Find(id);
            if (viewdatatable == null)
            {
                return HttpNotFound();
            }
            return View(viewdatatable);
        }

        //
        // POST: /DataTable/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(string id)
        {
            ViewDataTable viewdatatable = db.ViewDataTables.Find(id);
            db.ViewDataTables.Remove(viewdatatable);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }

    }
}